package com.example.shixunandjavagotoyangchen.BoosYang.Day002;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Presenter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandContion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1102.BrandPresenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay002_1102 extends BasterFragment implements OnRefreshLoadMoreListener, BrandContion.vier {

    public static SmartRefreshLayout BrandSmartRefreshLayout;
    private RecyclerView BrandRecyclerView;
    public boolean isning = true;
    public BrandAdpter adpter;
    public BrandPresenter presenter;

    @Override
    public int BandLayout()
    {
        return R.layout.fragment_blank_fragment_day002_1102;
    }

    @Override
    public void initView() {

        BrandSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Brand_SmartRefreshLayout);
        BrandRecyclerView = (RecyclerView) findViewById(R.id.Brand_RecyclerView);
        BrandRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        BrandSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        presenter = new BrandPresenter(this,new BrandModel());
        presenter.branding("Home_zidingyi.php");
    }

    @Override
    public void initDate() {

    }


    @Override
    public void getvier(List<BrandBean.ShujuBean> dataBeans) {
        BrandSmartRefreshLayout.finishLoadMore();
        BrandSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new BrandAdpter(dataBeans);
            BrandRecyclerView.setAdapter(adpter);
        }else {
            if (isning){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        isning =false;
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (isning){
            Log.i("aaa","la1");
        }
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();

    }

}
